package com.api.gbhg.liubing.web;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.liubing.dao.NotForContractWorkersDao;
import com.api.gbhg.daiyanlu.DataPrintCopyUtil.FormatUtil;
import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import com.api.gbhg.zengping.web.PropertyManagementAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : liubing
 * @date :  2020/12/30 10:30
 * 不占编合同工劳务费
 */
public class NotForContractWorkersAction {
    public static final Logger LOGGER= LoggerFactory.getLogger(PropertyManagementAction.class);
    private PropertyManagementCostDao rmcd=new PropertyManagementCostDao();
    @POST
    @Path("/getNotForContractWorkersAction")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public String getNotForContractWorkersAction(Map<String,String> param) {
//        String status =  param.get("status");//状态
//        Integer pageNum= Integer.valueOf(param.get("pageNum"));//页数
//        Integer pageSize= Integer.valueOf(param.get("pageSize"));//显示数量

        NotForContractWorkersDao dao = new NotForContractWorkersDao();
        String requestId=param.get("requestId");
        RecordSetTrans mainTable = dao.getMainTable(requestId);//获取主表数据
        PageEntity page = new PageEntity();
//        page.setPageNumber(pageNum);
//        page.setpageSize(pageSize);
//        int total = dao.getMainTableCount(status);//获取数据总条数
//        page.setTotal(total);//数据总条数
//        page.setPages((total + pageSize - 1) / pageSize);
        Map<String,Object>[] map=new HashMap[mainTable.getArray().size()];
        int i=0;
        while (mainTable.next()){
            map[i]=new HashMap<>();
            map[i].put("lcid",mainTable.getInt("lcid"));//流程id
            map[i].put("lcjlsqjlid",mainTable.getInt("lcjlsqjlid"));  //流程记录申请记录id
            map[i].put("xmmin",mainTable.getString("xmmin"));//项目名称
            RecordSet sbdw = rmcd.getSBDWById(mainTable.getInt("sbdw"));
            sbdw.next();
            map[i].put("sbdw",sbdw.getString("SUBCOMPANYNAME")); // 申报单位
            RecordSet sbks = rmcd.getSBKSById(mainTable.getInt("sbks"));
            sbks.next();
            map[i].put("sbks",sbks.getString("departmentmark"));// 申报科室
            RecordSet jbr = rmcd.getUserNameById(mainTable.getInt("jbr"));
            jbr.next();
            String loginid = jbr.getString("loginid");
            if(loginid==""){
                loginid="系统管理员";
            }
            map[i].put("jbr",loginid);  //编报人
            BigDecimal hwgz=new BigDecimal("0.00");
            BigDecimal gc=new BigDecimal("0.00");
            BigDecimal fw=new BigDecimal("0.00");
            BigDecimal xecg=new BigDecimal("0.00");

            if (!mainTable.getString("hwgz").equals("")){
                hwgz=hwgz.add(new BigDecimal(mainTable.getDouble("hwgz")));
            }
            if (!mainTable.getString("gc").equals("")){
                gc=gc.add(new BigDecimal(mainTable.getDouble("gc")));
            }
            if (!mainTable.getString("fw").equals("")){
                fw=fw.add(new BigDecimal(mainTable.getDouble("fw")));
            }
            if (!mainTable.getString("xecg").equals("")){
                xecg=xecg.add(new BigDecimal(mainTable.getDouble("xecg")));
            }
            map[i].put("yszje",hwgz.add(gc).add(fw).add(xecg).toString());//政府采购预算
            map[i].put("hwgz", hwgz.toString());//货物购置
            map[i].put("gc", gc.toString());//修缮工程
            map[i].put("fw",fw.toString());//服务预算
            map[i].put("xecg", xecg.toString());//小额采购
            RecordSet rs = dao.getDetailedTable(mainTable.getString("requestid"), 1);
            BigDecimal bzs=new BigDecimal("0.00");//人数
            BigDecimal xgyrs=new BigDecimal("0.00");//岗位工资
            BigDecimal bzbhtgrs=new BigDecimal("0.00");//年功工资
            BigDecimal debzmrmn=new BigDecimal("0.00");//住房公积金
            BigDecimal qnzjxq=new BigDecimal("0.00");//技术等级工资
            BigDecimal bz=new BigDecimal("0.00");//绩效工资
            BigDecimal shbt=new BigDecimal("0.00");//生活补贴
            BigDecimal hdcybt=new BigDecimal("0.00");//海岛船员补贴
            BigDecimal dwyjsbf=new BigDecimal("0.00");//单位应缴社保费
            BigDecimal jbf=new BigDecimal("0.00");//加班费
            BigDecimal nhj=new BigDecimal("0.00");//年合计
            BigDecimal ngwbt=new BigDecimal("0.00");//年高温补帖
            BigDecimal njsj=new BigDecimal("0.00");//年计生奖
            BigDecimal nwwf=new BigDecimal("0.00");//年慰问费
            BigDecimal nzkhj=new BigDecimal("0.00");//年终考核奖
            BigDecimal nys=new BigDecimal("0.00");//年预算
            BigDecimal je=new BigDecimal("0.00");//金额
            while (rs.next()){
                bzs = bzs.add(new BigDecimal(rs.getDouble("bzs")));
                xgyrs=xgyrs.add(new BigDecimal(rs.getDouble("xgyrs")));
                bzbhtgrs=bzbhtgrs.add(new BigDecimal(rs.getDouble("bzbhtgrs")));
                debzmrmn=debzmrmn.add(new BigDecimal(rs.getDouble("debzmrmn")));
                qnzjxq=qnzjxq.add(new BigDecimal(rs.getDouble("qnzjxq")));
                bz=bz.add(new BigDecimal(rs.getDouble("bz")));
                shbt=shbt.add(new BigDecimal(rs.getDouble("shbt")));
                hdcybt=hdcybt.add(new BigDecimal(rs.getDouble("hdcybt")));
                dwyjsbf=dwyjsbf.add(new BigDecimal(rs.getDouble("dwyjsbf")));
                jbf=jbf.add(new BigDecimal(rs.getDouble("jbf")));
                nhj=nhj.add(new BigDecimal(rs.getDouble("nhj")));
                ngwbt=ngwbt.add(new BigDecimal(rs.getDouble("ngwbt")));
                njsj=njsj.add(new BigDecimal(rs.getDouble("njsj")));
                nwwf=nwwf.add(new BigDecimal(rs.getDouble("nwwf")));
                nzkhj=nzkhj.add(new BigDecimal(rs.getDouble("nzkhj")));
                //nys=nysbzs.add(new BigDecimal(rs.getInt("nys")));
                je=je.add(new BigDecimal(rs.getDouble("je")));
            }
            map[i].put("bzs",bzs.toString());//人数
            map[i].put("xgyrs",xgyrs.toString());//岗位工资
            map[i].put("bzbhtgrs",bzbhtgrs.toString());//年功工资
            map[i].put("debzmrmn",debzmrmn.toString());//住房公积金
            map[i].put("qnzjxq",qnzjxq.toString());//技术等级工资
            map[i].put("bz",bz.toString());//绩效工资
            map[i].put("shbt",shbt.toString());//生活补贴
            map[i].put("hdcybt",hdcybt.toString());//海岛船员补贴
            map[i].put("dwyjsbf",dwyjsbf.toString());//单位应缴社保费
            map[i].put("jbf",jbf.toString());//加班费
            map[i].put("nhj",nhj.toString());//年合计
            map[i].put("ngwbt",ngwbt.toString());//年高温补帖
            map[i].put("njsj",njsj.toString());//年计生奖
            map[i].put("nwwf",nwwf.toString());//年慰问费
            map[i].put("nzkhj",nzkhj.toString());//年终考核奖
            map[i].put("nys",mainTable.getString("yszje"));//年预算
            map[i].put("je",je.toString());//金额
            i++;
        }
        page.setList(map);
        page.setFromtable("uf_bzbhtglwf");
        return  JSON.toJSONString(page);
    }

    //不占编合同工劳务费
    public String getNotForContractWorkersAction1(String requestId) {
//        String status =  param.get("status");//状态
//        Integer pageNum= Integer.valueOf(param.get("pageNum"));//页数
//        Integer pageSize= Integer.valueOf(param.get("pageSize"));//显示数量

        NotForContractWorkersDao dao = new NotForContractWorkersDao();
//        String requestId=param.get("requestId");
        RecordSetTrans mainTable = dao.getMainTable(requestId);//获取主表数据
        PageEntity page = new PageEntity();
//        page.setPageNumber(pageNum);
//        page.setpageSize(pageSize);
//        int total = dao.getMainTableCount(status);//获取数据总条数
//        page.setTotal(total);//数据总条数
//        page.setPages((total + pageSize - 1) / pageSize);
        Map<String,Object>[] map=new HashMap[mainTable.getArray().size()];
        int i=0;
        while (mainTable.next()){
            map[i]=new HashMap<>();
            map[i].put("lcid",mainTable.getInt("lcid"));//流程id
            map[i].put("lcjlsqjlid",mainTable.getInt("lcjlsqjlid"));  //流程记录申请记录id
            map[i].put("xmmin",mainTable.getString("xmmin"));//项目名称
            RecordSet sbdw = rmcd.getSBDWById(mainTable.getInt("sbdw"));
            sbdw.next();
            map[i].put("sbdw",sbdw.getString("SUBCOMPANYNAME")); // 申报单位
            RecordSet sbks = rmcd.getSBKSById(mainTable.getInt("sbks"));
            sbks.next();
            map[i].put("sbks",sbks.getString("departmentmark"));// 申报科室
            RecordSet jbr = rmcd.getUserNameById(mainTable.getInt("jbr"));
            jbr.next();
            String loginid = jbr.getString("loginid");
            if(loginid==""){
                loginid="系统管理员";
            }
            map[i].put("jbr",loginid);  //编报人
            BigDecimal hwgz=new BigDecimal("0.00");
            BigDecimal gc=new BigDecimal("0.00");
            BigDecimal fw=new BigDecimal("0.00");
            BigDecimal xecg=new BigDecimal("0.00");

            if (!mainTable.getString("hwgz").equals("")){
                hwgz=hwgz.add(new BigDecimal(mainTable.getDouble("hwgz")));
            }
            if (!mainTable.getString("gc").equals("")){
                gc=gc.add(new BigDecimal(mainTable.getDouble("gc")));
            }
            if (!mainTable.getString("fw").equals("")){
                fw=fw.add(new BigDecimal(mainTable.getDouble("fw")));
            }
            if (!mainTable.getString("xecg").equals("")){
                xecg=xecg.add(new BigDecimal(mainTable.getDouble("xecg")));
            }
            map[i].put("yszje",hwgz.add(gc).add(fw).add(xecg).toString());//政府采购预算
            map[i].put("hwgz", hwgz.toString());//货物购置
            map[i].put("gc", gc.toString());//修缮工程
            map[i].put("fw",fw.toString());//服务预算
            map[i].put("xecg", xecg.toString());//小额采购
            RecordSet rs = dao.getDetailedTable(mainTable.getString("requestid"), 1);
            double bzs=0;//人数
            double xgyrs=0;//岗位工资
            double bzbhtgrs=0;//年功工资
            double debzmrmn=0;//住房公积金
            double qnzjxq=0;//技术等级工资
            double bz=0;//绩效工资
            double shbt=0;//生活补贴
            double hdcybt=0;//海岛船员补贴
            double dwyjsbf=0;//单位应缴社保费
            double jbf=0;//加班费
            double nhj=0;//年合计
            double ngwbt=0;//年高温补帖
            double njsj=0;//年计生奖
            double nwwf=0;//年慰问费
            double nzkhj=0;//年终考核奖
            double nys=0;//年预算
            double je=0;//金额
            while (rs.next()){
                if(!rs.getString("bzs").equals("")) {
                    bzs += rs.getDouble("bzs");
                }
                if(!rs.getString("xgyrs").equals("")) {
                    xgyrs += rs.getDouble("xgyrs");
                }
                if(!rs.getString("bzbhtgrs").equals("")) {
                    bzbhtgrs += rs.getDouble("bzbhtgrs");
                }
                if(!rs.getString("debzmrmn").equals("")) {
                    debzmrmn += rs.getDouble("debzmrmn");
                }
                if(!rs.getString("qnzjxq").equals("")) {
                    qnzjxq += rs.getDouble("qnzjxq");
                }
                if(!rs.getString("bz").equals("")) {
                    bz += rs.getDouble("bz");
                }
                if(!rs.getString("shbt").equals("")) {
                    shbt += rs.getDouble("shbt");
                }
                if(!rs.getString("hdcybt").equals("")) {
                    hdcybt += rs.getDouble("hdcybt");
                }
                if(!rs.getString("dwyjsbf").equals("")) {
                    dwyjsbf += rs.getDouble("dwyjsbf");
                }
                if(!rs.getString("jbf").equals("")) {
                    jbf += rs.getDouble("jbf");
                }
                if(!rs.getString("nhj").equals("")) {
                    nhj += rs.getDouble("nhj");
                }
                if(!rs.getString("ngwbt").equals("")) {
                    ngwbt += rs.getDouble("ngwbt");
                }
                if(!rs.getString("njsj").equals("")) {
                    njsj += rs.getDouble("njsj");
                }
                if(!rs.getString("nwwf").equals("")) {
                    nwwf += rs.getDouble("nwwf");
                }
                if(!rs.getString("nzkhj").equals("")) {
                    nzkhj += rs.getDouble("nzkhj");
                }
                //nys=nysbzs.add(new BigDecimal(rs.getInt("nys")));
                if(!rs.getString("je").equals("")) {
                    je += rs.getDouble("je");
                }
            }
            map[i].put("bzs", FormatUtil.DmFormat(bzs));//人数
            map[i].put("xgyrs",FormatUtil.DmFormat(xgyrs/10000));//岗位工资
            map[i].put("bzbhtgrs",FormatUtil.DmFormat(bzbhtgrs/10000));//年功工资
            map[i].put("debzmrmn",FormatUtil.DmFormat(debzmrmn/10000));//住房公积金
            map[i].put("qnzjxq",FormatUtil.DmFormat(qnzjxq/10000));//技术等级工资
            map[i].put("bz",FormatUtil.DmFormat(bz/10000));//绩效工资
            map[i].put("shbt",FormatUtil.DmFormat(shbt/10000));//生活补贴
            map[i].put("hdcybt",FormatUtil.DmFormat(hdcybt/10000));//海岛船员补贴
            map[i].put("dwyjsbf",FormatUtil.DmFormat(dwyjsbf/10000));//单位应缴社保费
            map[i].put("jbf",FormatUtil.DmFormat(jbf/10000));//加班费
            map[i].put("nhj",FormatUtil.DmFormat(nhj/10000));//年合计
            map[i].put("ngwbt",FormatUtil.DmFormat(ngwbt/10000));//年高温补帖
            map[i].put("njsj",FormatUtil.DmFormat(njsj/10000));//年计生奖
            map[i].put("nwwf",FormatUtil.DmFormat(nwwf/10000));//年慰问费
            map[i].put("nzkhj",FormatUtil.DmFormat(nzkhj/10000));//年终考核奖
            map[i].put("nys",FormatUtil.DmFormat(mainTable.getDouble("yszje")/10000));//年预算
            map[i].put("je",FormatUtil.DmFormat(je/10000));//金额
            i++;
        }
        page.setList(map);
        page.setFromtable("uf_bzbhtglwf");
        return  JSON.toJSONString(page);
    }

}
